﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace Business.Models
{
    public class TruongHoc
    {
        public enum LOAI_TRUONG_HOC { CAP_1 = 1, CAP_2 = 2, CAP_3 = 3 };

        [Key]
        [Required]
        public int IdTruongHoc { get; set; }
        [Required]
        [Display()]
        public string TenTruongHoc { get; set; }
        [Required]
        public byte LoaiTruong { get; set; }
        [Required]
        public string DiaChi { get; set; }
        [Required]
        public string DienThoai { get; set; }
        [Required]
        public DateTime NgayTao { get; set; }
        [Required]
        public string NguoiPhuTrach { get; set; }
        [Required]
        public string DienThoai_NguoiPhuTrach { get; set; }
        [Required]
        public string Email_NguoiPhuTrach { get; set; }
        [Required]
        public int Quota { get; set; }
        public bool HoatDong { get; set; }

        public int IdDiaDiem { get; set; }
        [ForeignKey("IdDiaDiem")]
        public virtual DiaDiem diaDiem { get; set; }
        public int NguoiTao { get; set; }
        [ForeignKey("NguoiTao")]
        public virtual DaiLy daiLy { get; set; }
        
    }

    public class TruongHocConfiguration : EntityTypeConfiguration<TruongHoc>
    {

        public TruongHocConfiguration()
            : base()
        {

            HasKey(d => d.IdTruongHoc);
            Property(d => d.IdTruongHoc).
                HasColumnName("IdTruongHoc").
                HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).
                IsRequired();
            Property(d => d.TenTruongHoc).
                HasColumnName("TenTruongHoc").
                IsRequired();
            Property(d => d.LoaiTruong).
                HasColumnName("LoaiTruong").
                IsRequired();
            Property(d => d.DiaChi).
                HasColumnName("DiaChi").
                IsRequired();
            HasRequired(x => x.diaDiem).
            WithMany().
                Map(x => x.MapKey("IdDiaDiem"));
            Property(d => d.DienThoai).
                HasColumnName("DienThoai").
                IsRequired();
            Property(d => d.NgayTao).
                HasColumnName("NgayTao").
                IsRequired();
            Property(d => d.NguoiPhuTrach).
                HasColumnName("NguoiPhuTrach").
                IsRequired();
            Property(d => d.DienThoai_NguoiPhuTrach).
                 HasColumnName("DienThoai_NguoiPhuTrach").
                 IsRequired();
            Property(d => d.Email_NguoiPhuTrach).
                 HasColumnName("Email_NguoiPhuTrach").
                 IsRequired();
            Property(d => d.Quota).
                 HasColumnName("Quota").
                 IsRequired();
            Property(d => d.HoatDong).
                 HasColumnName("HoatDong").
                 IsRequired();
            HasRequired(x => x.daiLy).
            WithMany().
                Map(x => x.MapKey("NguoiTao"));
            ToTable("TruongHoc", "dbo");
        }

    }
}